import React, { useEffect, useState } from 'react';
import {
  MenuFoldOutlined,
  MenuUnfoldOutlined,
  UploadOutlined,
  UserOutlined,
  VideoCameraOutlined,
} from '@ant-design/icons';
import { Button, Layout, Menu, theme } from 'antd';
import {Switch,Route,Redirect} from 'react-router-dom'
import Home from './Home/Home';
import shezhi from './Home/Shezhi';
import { useHistory } from 'react-router-dom/cjs/react-router-dom.min';
import { useDispatch } from 'react-redux';
const { Header, Sider, Content } = Layout;
import {async_getshezhi} from '../store/crmslice'
const Admin = (props) => {
  const [collapsed, setCollapsed] = useState(false);
  const {
    token: { colorBgContainer, borderRadiusLG },
  } = theme.useToken();
  let history=useHistory()
  let dispatch=useDispatch()
  useEffect(()=>{
    dispatch(async_getshezhi())
  },[])
  return (
    <Layout>
      <Sider trigger={null} collapsible collapsed={collapsed}>
        <div className="demo-logo-vertical" />
        <Menu
          theme="dark"
          mode="inline"
          defaultOpenKeys={['',props.location.pathname]}
          defaultSelectedKeys={[props.location.pathname]}
          items={[
            {
              key: '/admin/home',
              icon: <UserOutlined />,
              label: '首页',
            },
            {
              key: '',
              icon: <VideoCameraOutlined />,
              label: '系统管理',
              children:[
                {
                    key: '/admin/shezhi',
                    icon: <UploadOutlined />,
                    label: '参数设置',
                  },
              ]
            },
          ]}
          onSelect={(path)=>{
            history.push(path.key)
          }}
        />
      </Sider>
      <Layout style={{height:"100vh"}}>
        <Header style={{ padding: 0, background: colorBgContainer }}>
          <Button
            type="text"
            icon={collapsed ? <MenuUnfoldOutlined /> : <MenuFoldOutlined />}
            onClick={() => setCollapsed(!collapsed)}
            style={{
              fontSize: '16px',
              width: 64,
              height: 64,
            }}
          />
        </Header>
        <Content
          style={{
            margin: '24px 16px',
            padding: 24,
            minHeight: 280,
            background: colorBgContainer,
            borderRadius: borderRadiusLG,
          }}
        >
         <Switch>
    <Route path='/admin/home' component={Home}></Route>
    <Route path='/admin/shezhi' component={shezhi}></Route>
    <Redirect from='/admin' to='/admin/home'></Redirect>
  </Switch>
        </Content>
      </Layout>
    </Layout>
  );
};
export default Admin;